
public class Account {

	String id;
	String name;
	int balance = 0;

	public Account(String id, String name) {
		this.id = id;
		this.name = name;
	}

	public Account(String id, String name, int balance) {
		this.id = id;
		this.name = name;
		this.balance = balance;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public int getBalance() {
		return balance;
	}

	public int credit(int amount) {
		balance += amount;
		return balance;
	}

	public int debit(int amount) {
		if (amount <= balance) {
			balance -= amount;
		} else {
			System.out.println("Amount exceeded balance");
		}

		return balance;
	}

	public String toString() {
		String s;
		s = "Account:[id=" + id + ",name=" + name + ",balance=" + balance + "]";
		return s;
	}

	public int transferTo(Account another, int amount) {
		if (amount <= balance) {
			another.balance += amount;
			this.debit(amount);
		} else {
			this.debit(amount);
		}
		return another.balance;
	}

}
